package cn.dglydrpy.study.j2ee.neo4j;

/**
 * 访问外置的neo4j
 */
import org.neo4j.driver.*;

// 静态方法导入
import static  org.neo4j.driver.Values.parameters;
public class Neo4jServerMain {
    public static void main(String[] args) {
        Driver driver = GraphDatabase.driver("bolt://192.168.80.128:7687",
                AuthTokens.basic("neo4j","147258"));
        // 获取会话对象
        Session  session = driver.session();
        String  cql = "MATCH(p:Person) WHERE p.money > $money return p.name AS name,p.money AS money " +
                " order by p.money";
 
        Result  result = session.run(cql,parameters("money",100));
        while (result.hasNext()){
            Record record = result.next();
            System.out.println(record.get("name").asString() + ","+record.get("money").asDouble());
        }
        
//        session.close();
//        driver.close();

        String  cqlfind = "MATCH p=shortestPath((person:Person{name:$startName})-[*1..4]-(person2:Person {name:$endName})) return p";
        Result  result2 = session.run(cqlfind,parameters("startName","王启年","endName","九品射手燕小乙"));
        while (result2.hasNext()){
            Record record = result2.next();
            System.out.println(record);
        }
        session.close();
        driver.close();
    }
}
